import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ModularMain implements Imodular {

    public DmjMain dmjMain;
    public List<String> downloadingList =new ArrayList<String>();
    public List<String> waitList =new ArrayList<String>();
    public String playing = "";
    public String getMusicIdUrl = "http://localhost:3000/search?keywords=";
    public String dowByMusicIdUrl = "http://localhost:3000/song/url?id=";
    public String modularName() {
        return "点歌姬";
    }
    public String version() {
        return "V0.0.1";
    }
    public Boolean next = false;
    public int maxMusic = 5;
    public Boolean stop = false;
    public Boolean isSetting = false;

    public void newDmCall(JSONObject dmJSONObject) {
        if (stop){
            return;
        }
        String dm = dmJSONObject.getString("text");
        if (dm.startsWith("点歌 ") & downloadingList.size()+waitList.size() <= maxMusic){
            WYYTool wyyTool = new WYYTool(this,dmjMain,dm.replace("点歌 ",""));
            wyyTool.start();
        }

    }

    public void modularInit(DmjMain dmjMain1) {
        dmjMain = dmjMain1;
        dmjMain.newLogCallback(modularName()+version());
        File file = new File("./music");
        if (!file.exists()) {
            file.mkdirs();
        }
        MusicPlayer player = new MusicPlayer(this,dmjMain);
        player.start();
    }

    public void Setting() {
        if (!isSetting){
            Controller controller = new Controller();
            try {
                controller.runSetting();
            }catch (Exception e){
                e.printStackTrace();
            }
            isSetting = true;
        }
    }

    public static void main(String[] args) {
        DmjMain dmjMain = new DmjMain();
        ModularMain modularMain = new ModularMain();
        modularMain.dmjMain = dmjMain;
        modularMain.Setting();
    }
}